package RJZ.Rainbow.Controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.HashMap;
import java.util.Map;


public class Tips {

    JOptionPane pane;
    JDialog dialog ;
    Timer timer;
    Map<String, String> stringmap=new HashMap<>();
    public Tips() {
        pane = new JOptionPane(null, JOptionPane.INFORMATION_MESSAGE);
        dialog = pane.createDialog(null, "服务器返回结果");
        dialog.setModal(false);
        timer=new Timer(10000, new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                pane.setVisible(false);
                dialog.setVisible(false);
            }
        });
        stringmap.put("111","订单验证成功");
        stringmap.put("112","订单投件码验证失败");
        stringmap.put("113","订单入库成功");
        stringmap.put("114","订单入库失败");
        stringmap.put("115","投件码不对应本柜子，对应柜子投件");
        stringmap.put("116","取件码不对应本柜子");
        stringmap.put("117","订单不存在或已超出柜子的最大容量");
        stringmap.put("121","取件码验证成功");
        stringmap.put("122","取件码验证失败");
        stringmap.put("123","订单出库成功");
        stringmap.put("124","订单出库失败");
    }
    public void match(String cop,String msg){
        String title=stringmap.get(cop);
        tip(msg+title);
    }

    public void tip(String msg){
        pane.setMessage(msg);
        pane.setVisible(true);
        dialog.setVisible(true);
        timer.start();
    }

}
